<?php

$oper = $_POST['oper'];

if (!isset($oper))
{
	die("Unknown command");
}

require('../dbconnect.inc.php');
try
{
	$dbh->beginTransaction();

	switch ($oper)
	{

		case 'det-add':
		
			$sth = $dbh->prepare('INSERT INTO event_items (e_id, sel_type, sel_param, act_type, act_param) VALUES(:e_id, :sel_type, :sel_param, :act_type, :act_param)');

			$sth->bindParam(':e_id', intval($_POST['e_id']), PDO::PARAM_INT);
			$sth->bindParam(':sel_type', intval($_POST['sel_type']), PDO::PARAM_INT);
			$sth->bindParam(':sel_param', intval($_POST['sel_param']), PDO::PARAM_INT);
			$sth->bindParam(':act_type', intval($_POST['act_type']), PDO::PARAM_INT);
			$sth->bindParam(':act_param', intval($_POST['act_param']), PDO::PARAM_INT);

			$sth->execute();

		break;
        
		case 'edit':
			$sth = $dbh->prepare('update events set name=? where e_id=?');
			$sth->execute(array($_POST['name'], $_POST['id']));
		break;

		case 'add':
			$sth = $dbh->prepare('insert into events (e_id, name) values (?,?)');
			$sth->execute(array($_POST['id'], $_POST['name']));
		break;

		case 'del':

			$sth = $dbh->prepare('delete from event_items where e_id=?');
			$sth->execute(array($_POST['id']));

			$sth = $dbh->prepare('delete from events where e_id=?');
			$sth->execute(array($_POST['id']));

		break;

		case 'det-del':
			
			$all = explode('-', $_POST['id']);

			echo $_POST['id'];

			print_r($all);

			$sth = $dbh->prepare('delete from event_items where e_id=? and sel_type=? and sel_param=? ');
			$sth->execute($all);

		break;

	}

	$dbh->commit();
}
catch (Exception $e)
{
	$dbh->rollBack();
}


?>